package com.hjm.project.terminal.changeFeeRecord.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hjm.project.agentInfo.agentInfo.domain.AgentInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.terminal.changeFeeRecord.domain.ChangeFeeRecord;
import com.hjm.project.terminal.changeFeeRecord.service.IChangeFeeRecordService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import javax.annotation.Resource;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 变更通讯费记录Controller
 * 
 * @author maker-platform
 * @date 2023-04-03
 */
@Controller
@RequestMapping("terminal/changeFeeRecord")
public class ChangeFeeRecordController extends BaseController {
    private String prefix = "terminal/changeFeeRecord";

    @Resource
    private IChangeFeeRecordService changeFeeRecordService;

    @RequiresPermissions("terminal/changeFeeRecord:view")
    @GetMapping()
    public String changeFeeRecord() {
        return prefix + "/changeFeeRecord";
    }

    /**
     * 查询变更通讯费记录列表
     */
    @RequiresPermissions("terminal:changeFeeRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ChangeFeeRecord changeFeeRecord) {
        startPage();
        List<ChangeFeeRecord> list = changeFeeRecordService.selectChangeFeeRecordList(changeFeeRecord);
        return getDataTable(list);
    }

    /**
     * 导出变更通讯费记录列表
     */
    @RequiresPermissions("terminal:changeFeeRecord:export")
    @Log(title = "变更通讯费记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ChangeFeeRecord changeFeeRecord) {
        List<ChangeFeeRecord> list = changeFeeRecordService.selectChangeFeeRecordList(changeFeeRecord);
        ExcelUtil<ChangeFeeRecord> util = new ExcelUtil<ChangeFeeRecord>(ChangeFeeRecord.class);
        return util.exportExcel(list, "changeFeeRecord");
    }

    /**
     * 新增变更通讯费记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存变更通讯费记录
     */
    @RequiresPermissions("terminal:changeFeeRecord:add")
    @Log(title = "变更通讯费记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ChangeFeeRecord changeFeeRecord) {
        return toAjax(changeFeeRecordService.insertChangeFeeRecord(changeFeeRecord));
    }

    /**
     * 修改变更通讯费记录
     */
    @GetMapping("/edit/{sysId}")
    public String edit(@PathVariable("sysId") Integer sysId, ModelMap mmap) {
        ChangeFeeRecord changeFeeRecord = changeFeeRecordService.selectChangeFeeRecordById(sysId);
        mmap.put("changeFeeRecord", changeFeeRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存变更通讯费记录
     */
    @RequiresPermissions("terminal:changeFeeRecord:edit")
    @Log(title = "变更通讯费记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ChangeFeeRecord changeFeeRecord) {
        return toAjax(changeFeeRecordService.updateChangeFeeRecord(changeFeeRecord));
    }

    /**
     * 删除变更通讯费记录
     */
    @RequiresPermissions("terminal:changeFeeRecord:remove")
    @Log(title = "变更通讯费记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(ChangeFeeRecord changeFeeRecord) {
        int result = changeFeeRecordService.deleteChangeFeeRecordById(changeFeeRecord);
        if(result == -2){
            return AjaxResult.error("已扣流量卡费,无法删除");
        }
        return toAjax(result);
    }

    /**
     * 获取 张万峰团下：资深总监
     * @return
     */
    @RequestMapping("/getAgentInfo")
    public String getAgentInfo(){
        return prefix + "/getAgentInfo";
    }

    /**
     * 查找带回服务商
     * @param agentInfo
     * @return
     */
    @PostMapping("/getAgentInfoList")
    @ResponseBody
    public TableDataInfo getAgentInfoList(AgentInfo agentInfo){
        startPage();
        return getDataTable(changeFeeRecordService.getAgentInfoList(agentInfo));
    }

    @PostMapping("/getSnCount")
    @ResponseBody
    public Map getSnCount(ChangeFeeRecord changeFeeRecord){
        Map map = new HashMap();
        int count = changeFeeRecordService.getSnCount(changeFeeRecord);
        map.put("counts",count);
        return map;
    }
}
